Skip to content

fix(psv): fix three crashes found in Vita core dumps - #289

Closed
NotTimm wants to merge 3 commits into
dragonflylee:devfrom
NotTimm:fix-psv-crashes
Closed

NotTimm wants to merge 3 commits into
dragonflylee:devfrom
NotTimm:fix-psv-crashes

Conversation

@NotTimm

@NotTimm NotTimm commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Three crashes found on a PS Vita 1000 from psp2dmp core dumps. Each was traced to its exact source line with symbols from a matching build.

1. Subtitle/audio selector crash (fix(player))

Opening the player settings could crash in SelectorCell::updateUI(). PlayerSetting passes mpv's sid (a track id) to the selector as an index into its track list. sub-add runs asynchronously, so a subtitle that is added (and selected) after track-list was read gives an sid past the end of the list. updateUI() then reads data[selection] out of bounds. The audio selector had the same pattern with aid - 1.

Fix: record each track's mpv id and look the current sid/aid up in that list, falling back to the first entry when it isn't listed. This affects all platforms, but on the Vita the slow network subtitle loading makes the race easy to hit.

2. %zd printf crash (fix(psv))

Seeking crashed in mpv's demuxer thread while formatting " %s/%d: %zd packets, %zd bytes%s%s\n" (part of the "Too many packets in the demuxer packet queues" warning). VitaSDK's newlib is built without _WANT_IO_C99_FORMATS, so z, t and j aren't supported. The conversion is skipped without consuming its argument, every following argument shifts, and %s dereferenced the packet count (0x613f). Any mpv or FFmpeg message with %z… before a %s can crash the same way.

Fix: wrap newlib's string and stream formatters at link time (-Wl,--wrap=_svfprintf_r,_vfprintf_r,vfprintf) and rewrite the format first. z and t are dropped (size_t/ptrdiff_t are 32-bit like int on the Vita) and j becomes ll. Verified in the final binary that vsnprintf, snprintf, sprintf and fprintf go through the wrapper.

3. mpv open thread crash (fix(psv))

Starting playback occasionally crashed in mp_cancel_set_parent() with a NULL slave. In mpv 0.36, start_open() calls cancel_open() when pthread_create() fails, which frees open_cancel, but open_demux_reentrant() then uses it anyway. Under memory pressure on the Vita thread creation can fail; retrying the same file then works.

Fix: a small mpv patch (scripts/vita/mpv/loadfile.patch) that fails the load instead. It bumps the mpv package to pkgrel=4.

Notes

  • The vita-packages workflow needs to be re-run to publish mpv-0.36.0-4 before the Vita CI build passes.
  • perf(psv): render mpv frames before the UI frame on GXM #288 also bumps the mpv package (to -4, for the decoder memory pool). Whichever PR is merged second needs that bumped to -5 in VITABUILD and build.yaml. I can rebase it.
  • Tested on a PS Vita 1000: the original crash cases no longer crash.

The selectors used mpv's sid/aid directly as an index into the track
list. sub-add runs asynchronously, so a subtitle added (and selected)
after track-list was read gives an sid past the end of the list, and
SelectorCell::updateUI() reads out of bounds and crashes. Record each
track's id and look the current sid/aid up instead, falling back to the
first entry when it is not listed.
VitaSDK's newlib is built without _WANT_IO_C99_FORMATS, so %zd, %zu, %td
and %jd are skipped without consuming their argument. Every following
argument shifts, and a later %s dereferences an integer. mpv's "Too many
packets in the demuxer packet queues" warning ("%s/%d: %zd packets...")
crashed the app this way after a seek.

Wrap newlib's string and stream formatters at link time and rewrite the
format first: z and t are dropped (size_t and ptrdiff_t are 32-bit like
int) and j becomes ll.
start_open() calls cancel_open() when pthread_create() fails, which
frees open_cancel. open_demux_reentrant() then passed the NULL
open_cancel to mp_cancel_set_parent() and crashed. This happens on the
Vita under memory pressure. Fail the load instead, so the app shows an
error and the next attempt can work.

Bumps the mpv package to pkgrel=4.
@dragonflylee

Copy link
Copy Markdown
Owner

Can it be split into 3 separate pull requests?

@NotTimm

NotTimm commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Sure, split into #290 (track selector crash), #291 (printf length modifiers) and #292 (mpv open thread). Closing this one in favor of those.

@NotTimm NotTimm closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants